/**
 * Created by fkjslee on 2017/12/31.
 */
 var url = "http://118.24.11.68:8080";
// var url = "http://172.24.8.233:8080";

window.onload = autoRun();

function autoRun() {
    var patientID = document.getElementById("patientID");
    patientID.value = GetQueryString("patientID");
}

function btnFinish() {
    var medicineName1 = document.getElementById("medicineName1");
    var medicineName2 = document.getElementById("medicineName2");
    var medicineName3 = document.getElementById("medicineName3");
    var medicineNum1 = document.getElementById("medicineNum1");
    var medicineNum2 = document.getElementById("medicineNum2");
    var medicineNum3 = document.getElementById("medicineNum3");
    var medicinePrice1 = document.getElementById("medicinePrice1");
    var medicinePrice2 = document.getElementById("medicinePrice2");
    var medicinePrice3 = document.getElementById("medicinePrice3");

    xmlHttp = new XMLHttpRequest();
    var data = "/storePrescription?patientID=" + GetQueryString("patientID") +
        "&account=" + GetQueryString("account") +
        "&medicineName1=" + medicineName1.value +
        "&medicineName2=" + medicineName2.value +
        "&medicineName3=" + medicineName3.value +
        "&medicineNum1=" + medicineNum1.value +
        "&medicineNum2=" + medicineNum2.value +
        "&medicineNum3=" + medicineNum3.value +
        "&medicinePrice1=" + medicinePrice1.value +
        "&medicinePrice2=" + medicinePrice2.value +
        "&medicinePrice3=" + medicinePrice3.value;
    xmlHttp.open("GET", url + data);
    xmlHttp.send();
    xmlHttp.onreadystatechange = function () {
        if(xmlHttp.readyState === 4) {
            if(xmlHttp.status === 200) {
                var text = JSON.parse(xmlHttp.responseText);
                var temp = "完成" + GetQueryString("patientID") + "的处方, 呼叫下一个";
                alert(temp);
                window.location.href= url + "/returnOrCheck/returnOrCheck.html" +
                        "?account=" + GetQueryString("account");
            }
        }
    }
}

/**
 * @return {null}
 */
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r !== null)return unescape(r[2]);
    return null;
}
